package com.homelock.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.homelock.service.LockUserService;
import com.pi.base.dto.result.AppResult;
import com.pi.http.base.controller.BaseController;

@RequestMapping("/lock/lockuser")
@RestController
public class LockUserController extends BaseController {

  @SuppressWarnings("unused")
  private static final Logger logger = LoggerFactory.getLogger(LockUserController.class);

  private LockUserService lockUserService;

  @Autowired
  public LockUserController(LockUserService lockUserService) {
    Assert.notNull(lockUserService, "锁具用户服务为空");
    this.lockUserService = lockUserService;
  }

  @RequestMapping("/add")
  public AppResult addLockUser(Long devId, String lockUserName, Boolean adminFlag,String mobile) {
    Long lockUserSeq = lockUserService.addLockUser(devId, lockUserName, adminFlag,mobile);
    return AppResult.newSuccessResult(lockUserSeq.toString());
  }

  @RequestMapping("/remove")
  public AppResult removeLockUser(Long devId, Long lockUserId) {
    lockUserService.removeLockUser(devId, lockUserId);
    return AppResult.OK;
  }

  @RequestMapping("/updateName")
  public AppResult updateLockUser(Long devId, Long userId, String lockUserName) {
    lockUserService.updateLockUser(devId, userId, lockUserName);
    return AppResult.OK;
  }

  @RequestMapping("/manage")
  public AppResult switchLockUserAdmin(Long devId, Long userId, Boolean adminFlag) {
    lockUserService.switchLockUserAdmin(devId, userId, adminFlag);
    return AppResult.OK;
  }

  @RequestMapping("/list")
  public AppResult listLockUser(Long devId) {
    return AppResult.newSuccessResult(lockUserService.queryLockUserList(devId));
  }
}
